﻿@model KhuyenMaiVang.DAL.Voucher

@{
    ViewBag.Title = "Thêm voucher";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}

@section heading{Thêm voucher}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<!-- Ajax upload avatar -->
        <script src="@Url.Content("~/Content/scripts/ajaxupload/fileuploader.js")" type="text/javascript"></script>
        <link href="@Url.Content("~/Content/scripts/ajaxupload/fileuploader.css")" rel="stylesheet" type="text/css" />
        <!-- CKEDtor-->
<script type="text/javascript" src="@Url.Content("~/Content/scripts/ckeditor/ckeditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/scripts/ckeditor/adapters/jquery.js")"></script>
<script type="text/javascript">
    function uploader() {
        var thumbUploader = new qq.FileUploader({
            element: document.getElementById('thumb-uploader'),
            action: '/Admin/Helper/UploadVoucherThumb/',
            debug: true,
            multiple: false,
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            onComplete: function (file, response) {
                var fullName = "/content/kmvdata/vouchers/thumbs/" + response;
                $('#previewThumb').attr('src', fullName);
                $('#previewThumb').height(100);
                $('input[id=Thumb]').val(fullName);
            }
        });
        var backgroundUploader = new qq.FileUploader({
            element: document.getElementById('background-uploader'),
            action: '/Admin/Helper/UploadVoucherBack/',
            debug: true,
            multiple: false,
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            onComplete: function (file, response) {
                var fullName = "/content/kmvdata/vouchers/backgrounds/" + response;
                $('#previewBackground').attr('src', fullName);
                $('#previewBackground').height(100);
                $('input[id=Background]').val(fullName);
            }
        });
    }
    function addRichText() {
        $('#Features').ckeditor(
            function () { }, { toolbar: 'Basic' }
        );
        $('#Requirements').ckeditor(function () { }, { toolbar: 'Basic' });
        $('#Body').ckeditor();
        $('#Description').ckeditor(function () { }, { toolbar: 'Basic' });
    }
    function processCreate() {
        uploader();
        addRichText();
        $('input[id=Title]').keyup(function () {
            var aa = $("#Title").val();
            $("#Title").val(aa);
            var as = '';
            as = aa.toLowerCase();
            as = as.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, "a");
            as = as.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, "e");
            as = as.replace(/ì|í|ị|ỉ|ĩ/g, "i");
            as = as.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ.+/g, "o");
            as = as.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, "u");
            as = as.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, "y");
            as = as.replace(/đ/g, "d");


            as = as.replace(/-+-| |\/|,/g, "-"); //thay thế 2- thành 1- 
            as = as.replace(/^\-+|\"|\-+$/g, "");

            $("#URLAlias").val(as);
        });
    };
    window.onload = processCreate;
</script>
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.URLAlias)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.URLAlias)
            @Html.ValidationMessageFor(model => model.URLAlias)
        </div>
        <br />
        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>
    <br />
        <div class="editor-label">
            @Html.LabelFor(model => model.Features)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Features)
            @Html.ValidationMessageFor(model => model.Features)
        </div>
        <br />
        <div class="editor-label">
            @Html.LabelFor(model => model.Requirements)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Requirements)
            @Html.ValidationMessageFor(model => model.Requirements)
        </div>
        <br />
        <div class="editor-label">
            @Html.LabelFor(model => model.Body)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Body)
            @Html.ValidationMessageFor(model => model.Body)
        </div>

        <br />
        <div class="editor-label">
            @Html.LabelFor(model => model.CostPrice)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.CostPrice)
            @Html.ValidationMessageFor(model => model.CostPrice)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SellPrice)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SellPrice)
            @Html.ValidationMessageFor(model => model.SellPrice)
        </div>

        <div class="editor-field">
            @Html.HiddenFor(model => model.CreatedTime)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.EndTime)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EndTime)
            @Html.ValidationMessageFor(model => model.EndTime)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.MinOrder)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MinOrder)
            @Html.ValidationMessageFor(model => model.MinOrder)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.MaxOrder)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MaxOrder)
            @Html.ValidationMessageFor(model => model.MaxOrder)
        </div>

        <div class="editor-field">
            @Html.HiddenFor(model => model.VoucherStatusID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CityID, "City")
        </div>
        <div class="editor-field">
            @Html.DropDownList("CityID", String.Empty)
            @Html.ValidationMessageFor(model => model.CityID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CategoryID, "Category")
        </div>
        <div class="editor-field">
            @Html.DropDownList("CategoryID", String.Empty)
            @Html.ValidationMessageFor(model => model.CategoryID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.BusinessID, "Business")
        </div>
        <div class="editor-field">
            @Html.DropDownList("BusinessID", String.Empty)
            @Html.ValidationMessageFor(model => model.BusinessID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Thumb)
        </div>
        <div id="thumb-uploader">
            
        </div>
        <img alt="" id="previewThumb" src="" height=""/>
        <div class="editor-field">
            @Html.HiddenFor(model => model.Thumb)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Background)
        </div>
        <div id="background-uploader">
            
        </div>
        <img alt="" id="previewBackground" src="" height=""/>
        <div class="editor-field">
            @Html.HiddenFor(model => model.Background)
        </div>

        <p>
            <input class="button" type="submit" value="Thêm voucher" />
        </p>
}

<div>
    @Html.ActionLink("Quay lại", "Index")
</div>
